/**
 * Created by zhangsi on 2015/11/4.
 */
var loginCtrl = new XFApp.client();
XFApp.client.prototype.login = {
    isSubmitting : false,
    successCode : 10000,
    urlItems : {
        loginUrl : basePath +"/ajaxLogin",
        homeUrl : basePath +"/index"
    },
    page : null,
    login : function(){
        var _this = this;
        if(_this.isSubmitting){
            return;
        }
        var username = $("#username").val();
        var password = $("#password").val();
        if(_this.isBlank(username) || _this.isBlank(password)){
            $("#error_span").html("用户名或者密码不能为空!");
            return;
        }
        $.ajax({
            url: _this.urlItems.loginUrl,
            data: $('#login_form').serialize(),
            dataType: 'json',
            type: 'post',
            success: function (data) {
                if(data.success){
                    window.location = _this.urlItems.homeUrl;
                }else{
                    $("#error_span").html(data.message);
                }
            },
            error: function (data) {
                $("#error_span").html("系统错误，联系管理员!");
            }
        });
    },
    isBlank : function(msg){
        if(msg == null || msg == 'undefined' || msg == ''){
            return true;
        }
        return false;
    },
    event : function(){
        var _this = this;
        $("#submit").on("click",function(){
                _this.login();
        });
    }
}

$(function(){
    loginCtrl.login.event();
});